﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Data;
using ScrumTable.BL.DM.DataManagement;
using Microsoft.Practices.Unity;
using ScrumTable.Config.ElementManagement;
using ScrumTable.UI.ViewModel.Data;
using ScrumTable.Config.ConfigManagement;
using ScrumTable.UI.ViewModel.Extension;

#endregion

namespace ScrumTable.UI.ViewModel.View
{
    /// <summary>
    /// Description of the class
    /// </summary>
    public class DynamicUiBoardViewModel : DynamicUiBase
    {

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------
     
        private ObservableCollection<IScrumItemViewModel<DomainBase>>[] _collections;
        private TargetConfig _config;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------  

        /// <summary>
        /// List of task in the ToDoState
        /// </summary>
        /// <value>List of task in the ToDoState</value>
        public override ObservableCollection<IScrumItemViewModel<DomainBase>>[] Collections
        {
            get
            {
                if (ScrumData.CurrentIteration != null)
                {
                    int i = 0;
                    foreach (var state in States)
                    {
                        _collections[i] = SetTaskOnList(state, ref _collections[i], ScrumData);
                        i++;
                    }
                    return _collections;
                }
                return null;
            }
        }


        public override TargetConfig Config
        {

            get { return _config; }
            set
            {
                _config = value;
                _collections = new ObservableCollection<IScrumItemViewModel<DomainBase>>[ElementManager.CalcMaxStatesForTarget(value)];
            }
        }

        public override IEnumerable<ScrumState> States
        {
            get { return ElementManager.GetStates(Config); }
        }

        #endregion


        
     
     
        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------
        

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Releases managed (c# or .net) resources.
        /// </summary>
        protected override void ReleaseManagedResources()
        {
            base.ReleaseManagedResources();
        } 
 
        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

          
        protected override void OnContextElementChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e is DomainChangedEventArgs && ((DomainChangedEventArgs)e).ContainsPropertyNames("State", "Priority", "Ranking"))
            {
                RefreshLists();
            }
        }

        protected override void OnContextCollectionChanged(object sender, DomainCollectionChangedEventArgs e)
        {
            RefreshLists();
        }

        #endregion
    }
}
